`
https://leetcode.cn/problems/first-bad-version/
`

/**
 * Definition for isBadVersion()
 * 
 * @param {integer} version number
 * @return {boolean} whether the version is bad
 * isBadVersion = function(version) {
 *     ...
 * };
 */

/**
 * @param {function} isBadVersion()
 * @return {function}
 */
var solution = function (isBadVersion) {
  /**
   * @param {integer} n Total versions
   * @return {integer} The first bad version
   */
  return function (n) {
    let left = 0, right = n
    while (left + 1 < right) {
      const mid = left + Math.floor((right - left) / 2)
      if (isBadVersion(mid)) {
        right = mid
      } else {
        left = mid
      }
    }
    return right
  };
};